package com.bigknow.appstore.proxy.db.impl;

import com.bigknow.appstore.proxy.db.IDBHelper;
import com.bigknow.appstore.proxy.entity.TCLog;
import com.bigknow.appstore.proxy.enumerate.SecurityType;
import org.mongodb.morphia.Datastore;

import static com.bigknow.appstore.common.Assert.assertNotNull;

/**
 * Created by chaos on 2016/9/29.
 */
public class MongodbHelper implements IDBHelper {

    private Datastore datastore;

    public MongodbHelper(Datastore datastore) {
        assertNotNull(datastore);
        this.datastore = datastore;
    }

    @Override
    public TCLog findTCLog(String resourceId, SecurityType securityType) {
        return datastore.find(TCLog.class).field("resId").equal(resourceId)
                .field("securityType").equal(securityType).get();
    }

    @Override
    public void saveTCLog(TCLog tcLog) {
        datastore.save(tcLog);
    }
}
